﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using Inicio.Entities;

namespace Inicio.Core.Repositories
{
    public class WorkTypeRepositorie
    {
        public List<Rendering> LoadWorkTypes(int lenderId, string conec)
        {
            List<Rendering> renderings = new List<Rendering>();

            using (SqlCeConnection cn = new SqlCeConnection(conec))
            {
                cn.Open();
                using (SqlCeCommand cmd = new SqlCeCommand(
                    "SELECT id, WorkTypeName FROM WorkType "
                        + "where("
                            + string.Format("{0}=lenderId) ORDER BY WorkTypeName ASC", lenderId), cn))
                {
                    using (SqlCeDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            renderings.Add(new Rendering((int)reader["id"], reader["WorkTypeName"].ToString()));
                        }
                    }
                }
            }
            return renderings;
        }

    }
}
